home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10845 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  69 lines

  1. Path: uuneo.neosoft.com!usenet
  2. From: Wmatthew@lan-aces.com (W. Matthews)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Default values for constructor arguments
  5. Date: 11 Mar 1996 14:40:46 GMT
  6. Organization: LAN-ACES, Inc.
  7. Message-ID: <4i1e1e$b7i@uuneo.neosoft.com>
  8. References: <4hjoof$5qk@newnews.iafrica.com>
  9. NNTP-Posting-Host: 198.65.178.8
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12. In article <4hjoof$5qk@newnews.iafrica.com>, Peter Golda <goldap@telkom11.telkom.co.za> says:
  13. >
  14. >Hi,
  15. >
  16. >I had a constructor for my MWMessageLog class as follows:
  17. >
  18. >    MWMessageLog(
  19. >        const RWCString& anExecutableCode,
  20. >        const RWCString& aSystemCode,
  21. >        const RWCString& aLogFilePath );
  22. >
  23. >where the class RWCString comes from the Rogue Wave development library
  24. >and is just a simple string class.
  25. >
  26. >Now, I wanted to add default values, so I wrote as follows (knowing that
  27. >RWCString has a constructor that constructs RWCString from char* and it
  28. >has an assignment operator):
  29. >
  30. >   MWMessageLog(
  31. >       ...
  32. >       ...
  33. >       const RWCString& aLogFilePath = "~/logs/" );
  34. >
  35. >but now the compiler moans that it doesn't like that since the default
  36. >value must be passed through a constructor. 
  37. >
  38. >So, I thought I'd create a static member variable in my class of
  39. >type RWCstring; initialise it to "~/logs/" and then use the variable's
  40. >name as my default value in the constructor. But that fails too.
  41. >
  42. >The C++ ARM has an example of something similar on page 143 (Ch8, Default 
  43. >Arguments) - but it doesn't seem to work...
  44. >
  45. >My question thus is:
  46. >
  47. >Can I use default values with classes/types that are not inbuilt, but
  48. >may be constructed of one inbuilt type value. If so, how can I do it
  49. >without making a big mess of things ?
  50. >
  51. >Thanks,
  52. >Pete.
  53. >
  54. >
  55. Perhaps you could do some type casting (although I agree with you, it should
  56. not be so hard to do):
  57.     ...
  58.     const RWCString& aLogFilePath = (RWCString)("~/logs/") );
  59.  
  60. ______________________________________________
  61. |Wyatt Matthews:       Tech Support Department |
  62. |WMATTHEW@LAN-ACES.COM        -Internet-       |
  63. |WMATTHEW.MHS@LAN-ACES          -MHS-          |
  64. |LAN-ACES Tech Support      (713)890-9786      |
  65. |LAN-ACES BBS               (713)890-9790      |
  66. |LAN-ACES Fax               (713)890-9731      |
  67. |LAN-ACES Sales             (713)890-9787      |
  68. ______________________________________________
  69.